package com.lf.sys.util;

import com.lf.sys.model.SysEmail;

public class MailUtils {
	public static MailBean getReMailBean(SysEmail sysEmail) {
		MailBean re = null;
		if (sysEmail == null) {
			return null;
		}
		if (sysEmail.getMailType().trim().equals("1")) {
			re = MailProperties.getQQMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
			re.setHost(sysEmail.getHost());
			re.setPort(sysEmail.getPort());
			re.setSocketFactoryPort(sysEmail.getPort());
		} else {
			switch (sysEmail.getMailType().trim()) {
			
			case "QQ":
				re = MailProperties.getQQMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
				break;
			case "aliyun":
				re = MailProperties.getALIMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
				break;
			case "yahoo":
				re = MailProperties.getYaHooMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
				break;
			case "exQQ":
				re = MailProperties.getEXQQMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
				break;
			case "gmail":
				re = MailProperties.getGoogleMailBean(sysEmail.isPOP3(), sysEmail.isSSL());
				break;
			}
		}
		re.setAccount(sysEmail.getAccount());
		re.setPassword(sysEmail.getPassword());
		return re;
	}

	public static MailBean getSendMailBean(SysEmail sysEmail) {
		MailBean send = null;
		if (sysEmail == null) {
			return null;
		}
		if (sysEmail.getMailType().trim().equals("1")) {
			send = MailProperties.getQQMailBean(sysEmail.isSSL());
			send.setHost(sysEmail.getSendHost());
			send.setPort(sysEmail.getSendPort());
			send.setSocketFactoryPort(sysEmail.getSendPort());

		} else {
			switch (sysEmail.getMailType().trim()) {
			case "163":
				send = MailProperties.get163MailBean(sysEmail.isSSL());
				break;
			case "QQ":
				send = MailProperties.getQQMailBean(sysEmail.isSSL());
				break;
			case "aliyun":
				send = MailProperties.getALIMailBean(sysEmail.isSSL());
				break;
			case "yahoo":
				send = MailProperties.getYaHooMailBean(sysEmail.isSSL());
				break;
			case "exQQ":
				send = MailProperties.getEXQQMailBean(sysEmail.isSSL());
				break;
			case "gmail":
				send = MailProperties.getGoogleMailBean(sysEmail.isSSL());
				break;
			}
		}
		send.setAccount(sysEmail.getAccount());
		send.setPassword(sysEmail.getPassword());
		return send;
	}
}
